
package preprocessor;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class CreateDataBase {

	public static void nmain(String[] args) throws ClassNotFoundException, SQLException{
		
		Class.forName("org.sqlite.JDBC");
	    Connection conn =
	      DriverManager.getConnection("jdbc:sqlite:test.db");
				
	    
	    Statement stat = conn.createStatement();
	    stat.executeUpdate("drop table if exists Nodes;");
	    stat.executeUpdate("create table Nodes (nKey INTEGER PRIMARY KEY, Name varchar(50), Type varchar(50), Category varchar(50));");
	    

	    stat.executeUpdate("drop table if exists NodesT;");
	    stat.executeUpdate("create table NodesT (nKey INTEGER PRIMARY KEY, Category varchar(50));");
	    
	    
	    stat.executeUpdate("drop table if exists Links;");
	    stat.executeUpdate("drop table if exists LinksT;");
	    
	    //added nkey for a hash set.
	    stat.executeUpdate("create table Links (nKey INTEGER PRIMARY KEY, Node1 INTEGER, 	Node2 INTEGER, lWeight INTEGER, FOREIGN KEY(Node1) REFERENCES Nodes(nKey), 	FOREIGN KEY(Node2) REFERENCES Nodes(nKey)  );");
	    
	    /*
	     * 
	     * Inserting into the node Table
	     * 
	     */
	    stat.executeUpdate("insert into Nodes (Name,Type) values ('Cat', 'WIKIPEDIA');");
	    stat.executeUpdate("insert into Nodes (Name,Type) values ('Dog', 'WIKIPEDIA');");
	    stat.executeUpdate("insert into Nodes (Name,Type) values ('Mouse', 'WIKIPEDIA');");
	    
	    /*
	     * 
	     * Conecting the links Table
	     * 
	     * 
	     */
	    stat.executeUpdate("insert into Links (Node1, Node2, lWeight) values (0, 1, 1);");
	    stat.executeUpdate("insert into Links (Node1, Node2, lWeight) values (1, 0, 1);");
	    stat.executeUpdate("insert into Links (Node1, Node2, lWeight) values (0, 2, 1);");
	    
	    
	    ResultSet rs = stat.executeQuery("SELECT * from Nodes where Name like 'Cat';");
	    while (rs.next()) {
	      System.out.println("name = " + rs.getString("name")); 
	      System.out.println("Type = " + rs.getString("Type")); 
	     
	    }
	    
	    rs.close();
	    conn.close();
	    
	    
	   //System.out.println(NodeTypes.WIKIPEDIA);
	    
	    
	    System.out.println("Finnished");
	    
		
	}
	
}
